#include <iostream>
#include <unistd.h>

#include "serialization.hpp"
#include "Sock.hpp"

void Usage()
{
    std::cout << "using warning, Please enter: " << std::endl;
    std::cout << "[./client ip port]" << std::endl;
}

int main(int argc, char *argv[])
{
    if (argc != 3)
    {
        Usage();
        return 10;
    }

    std::string ip = argv[1];
    uint16_t port = atoi(argv[2]);

    Sock sock;
    int sockfd = sock.Socket();
    int n = sock.Connect(sockfd, ip, port);
    if (n < 0)
    {
        std::cerr << "warning " << std::endl;
        exit(11);
    }

    while (true)
    {
        Request req(10, 30, '-');
        std::string result = req.Serialization();
        sock.Send(sockfd, result);
        sock.Revc(sockfd, result);
        std::cout << result << std::endl;

        sleep(1);
    }
    return 0;
}